home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4571 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: news.walrus.com!news
  2. From: fjordao@walrus.com (Felipe Jordao)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q] Dynamically allocating memory for a char*
  5. Date: Tue, 30 Jan 1996 22:41:42 GMT
  6. Organization: HAC
  7. Message-ID: <4em6te$pmj@walrus2.walrus.com>
  8. References: <4dmn1i$10t@walrus2.walrus.com> <NITIN.96Jan19095012@more.eng.sun.com> <4doph6$507@newsroom.hitc.com>
  9. NNTP-Posting-Host: p12.ts1.walrus.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. psand@eos.hitc.com (G. Patrick Sand) wrote:
  13.  : >In article <4dmn1i$10t@walrus2.walrus.com> fjordao@walrus.com (Felipe 
  14.  : Jordao) 
  15.  : >writes:
  16.  : How about this:
  17.  : use the cin.get( char* buf, int length, char term) method
  18.  : This reads into a buffer (buf) up to length bytes and null-terminates it 
  19.  : (dropping the last byte if the stream read in has length non-null 
  20.  : characters), until it hits the term character.
  21.  : Just pick a buffer size (like 512 or 1024) that you know they have no 
  22.  : right to exceed and you then manipulate the buffer to get your string...
  23.  : I found this in section 10.3.1 (p. 332) of The C++ Programming Language 
  24.  : (2nd Edition) by Stroustrup (ISBN 0-201-53992-6)--mine is copyrighted 
  25.  : 1991
  26.  
  27. Thanks for the tip.  I had seen this info and had even bought a C++
  28. book only on IOStreams (with a fish on the front) that's pretty good.
  29. Maybe I'm missing the point here.  If I use a buffer wouldn't that
  30. still mean that I have to allocate 512 or X amount of memory?  Will
  31. the buffer disappear immeadiately after I read the string and assign
  32. it?  I was trying to get away with assigning just the right amount of
  33. memory.  Or am I being stupidly picky? ;)
  34.  
  35. Felipe
  36.  
  37.